//package com.lfs.market.task;
//
//import com.lfs.market.constants.ProductConstant;
//import com.lfs.market.model.entity.Orders;
//import com.lfs.market.model.entity.ProductInfo;
//import com.lfs.market.service.OrdersService;
//import com.lfs.market.service.ProductInfoService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
//import static com.lfs.market.constants.OrderConstant.PAST_DUE;
//
///**
// * 定时任务用于标记过期订单，定时将未支付的订单2 进行过期处理0
// */
//@Slf4j
//@Component
//@EnableScheduling
//public class OrderTask {
//
//    @Autowired
//    OrdersService ordersService;
//
//    @Autowired
//    ProductInfoService productInfoService;
//
//    @Scheduled(fixedRate = 60000) // 每5分钟执行一次
//    public void checkAndMarkExpiredOrders() {
//        List<Orders> expiredOrders = ordersService.orderTaskDelete();
//        for (Orders order : expiredOrders) {
//            order.setStatus(PAST_DUE); // 标记为订单过期
//            ordersService.updateById(order);
//            log.info("订单{}已标记为过期", order.getOrderNo());
//
//            //订单过期未支付重新上架商品
//            String productId = order.getProductId();
//            ProductInfo productInfo = productInfoService.getById(productId);
//            productInfo.setStatus(ProductConstant.PUBLISH);
//            productInfoService.updateById(productInfo);
//        }
//    }
//}
